package com.sky;

import com.sky.Protocol.MessageFactory;
import com.sky.Protocol.MessageProtocol;
import com.sky.Sdk.ClientBootstrap;
import io.netty.channel.socket.SocketChannel;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class App
{
    static int count = 0;

    public static void main( String[] args ) throws InterruptedException {
//        ClientBootstrap clientBootstrap = new ClientBootstrap("doc.dn-pp.com",19000,50);
//        ClientBootstrap clientBootstrap = new ClientBootstrap("192.168.100.29",19000,120);
        ClientBootstrap clientBootstrap = new ClientBootstrap("127.0.0.1",19000,50);

//        ClientBootstrap clientBootstrap = new ClientBootstrap("192.168.111.113",19000,190);

        ExecutorService cachedThreadPool = Executors.newFixedThreadPool(1);
        cachedThreadPool.execute(new Runnable() {
            @Override
            public void run() {

                MessageFactory f = new MessageFactory();
                MessageProtocol msg = f.createMessage(2,"android client");



                while(true) {
//                    System.out.println("----------------------");
                    SocketChannel socketChannel = clientBootstrap.getSocketChannel();
                    if(socketChannel != null && socketChannel.isRegistered())
                    {
                        clientBootstrap.getSocketChannel().writeAndFlush(msg);

                        System.out.println("count = " + count);

                        count++;
                    }

                    try {
                        Thread.sleep(1200000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }


                }
            }
        });

        clientBootstrap.connect();

    }
}
